/*
 * @Author: your name
 * @Date: 2021-01-06 11:41:48
 * @LastEditTime: 2021-02-19 11:34:01
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \express-seed\service\imgService.js
 */
/* const path = require('path')
const fs = require("fs"); //node读取文件模块 */
const { selectImgsDao, addImgDao, delImgDao, addProjectImgDao } = require('../dao')
const { delImg } = require('../utils/utils');
module.exports = {
    //查询图片
    async selectImgService(id) {
        return await selectImgsDao(id)
    },
    //添加图片
    async addImgService(imgsInfo) {
        // 更具数据库返回结果写入图片
        return await addImgDao(imgsInfo)
    },
    //添加项目工程图片
    async addProjectImgService(imgsInfo, pid) {
        // 更具数据库返回结果写入图片
        return await addProjectImgDao(imgsInfo, pid)
    },
    //删除图片
    async delImgService(img_id) {
        const { results } = await module.exports.selectImgService(img_id)//查询图片路径
        const { status } = await delImgDao(img_id)//删除图片
        if (status) {
          return await delImg(results[0]['img_path'])//删除本地图片
        }
    }
}